﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace Weazel.Gezel.Model.Errors
{
  public class ErrorMessage
  {
    private List<object> components;

    private Position position;
    public Position Position
    {
      get { return position; }
    }

    /// <summary>
    /// Returns the content of this message in the form of a list 
    /// of error message components
    /// </summary>
    /// <value>List of error message components making up this message</value>
    public List<object> Components
    {
      get
      {
        return components;
      }
    }

    /// <summary>
    /// Creates an empty error message
    /// </summary>
    public ErrorMessage()
    {
      this.components = new List<object>();
    }

    public ErrorMessage(string message)
    {
      this.components = new List<object>();
      components.Add(message);
    }

    public void AddString(string message)
    {
      components.Add(message);
    }

    public void AddEntity(CommonEntity entity)
    {
      components.Add(entity);
    }

    public void AddPosition(Position pos)
    {
			// may be null
      components.Add(pos);
      this.position = pos;
    }


    /// <summary>
    /// Returns a string representation of this error message
    /// </summary>
    /// <returns>string respresentation of this error message</returns>
    public override string ToString()
    {
      StringBuilder str = new StringBuilder();
      foreach (object message in components)
      {
        if (message == null)
          str.Append("(message missing)");
        else
          str.Append(message.ToString());
      }

      return str.ToString();
    }

    public void ConsolePrettyPrint()
    {
      foreach (object message in components)
      {
        Console.Write(message.ToString());
      }

      Console.WriteLine();
    }
  }
}
